package clinicapoo.dao;

import clinicapoo.model.Medico;
import java.util.List;

/**
 *
 * @author fmontezuma
 */
public class MedicoDAO extends BaseDAO
{
	public void cadastrar(Medico m)
	{
		log.debug(m.toString());
		getEntityManager().persist(m);
	}

	public void atualizar(Medico m)
	{
		log.debug(m.toString());
		getEntityManager().flush();
	}

	public void excluir(Medico m)
	{
		log.debug(m.toString());
		getEntityManager().remove(m);
	}

	public Medico procurarPorCpf(String cpf)
	{
		log.debug("cpf: " + cpf);
		List<Medico> medicos = getEntityManager()
				.createQuery("from Medico m where m.cpf = :cpf")
				.setParameter("cpf", cpf).getResultList();
		if (medicos.isEmpty())
			return null;
		else
			return medicos.get(0);
	}

	public List<Medico> listar()
	{
		log.debug("Recuperando lista de médicos");
		return getEntityManager().createQuery("select object(m) from Medico m").getResultList();
	}
}
